package lwh.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import lwh.utils.DBOpenHelper;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class StopPointCopyService {
	private DBOpenHelper dbOpenHelper;

	public StopPointCopyService(Context context) {
		this.dbOpenHelper = new DBOpenHelper(context);
	}

	public List<HashMap<String, Object>> getInitList(String subsectionId,
			String childsubsectionId, String subitemId) {
		List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
		SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
		Cursor cursor = db
				.rawQuery(
						"select (select partition_name from exm_partition where partition_id=?) as subsection,(select partition_name from exm_partition where partition_id=?) as childSub,(select partition_name from exm_partition where partition_id=?) as subitem,exm_ckp_id,exm_ckp_name,exm_ckp_desc from exm_package_checkpoint where partition_id=?",
						new String[] { subsectionId, childsubsectionId,
								subitemId, subitemId });
		while (cursor.moveToNext()) {
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("exm_ckp_name",
					cursor.getString(cursor.getColumnIndex("exm_ckp_name")));
			item.put("exm_ckp_id",
					cursor.getString(cursor.getColumnIndex("exm_ckp_id")));
			item.put("exm_ckp_desc",
					cursor.getString(cursor.getColumnIndex("exm_ckp_desc")));
			item.put("subsection",
					cursor.getString(cursor.getColumnIndex("subsection")));
			item.put("childSub",
					cursor.getString(cursor.getColumnIndex("childSub")));
			item.put("subitem",
					cursor.getString(cursor.getColumnIndex("subitem")));
			data.add(item);
		}
		cursor.close();
		db.close();
		return data;
	}

	public void closeDBHelper() {
		dbOpenHelper.close();
	}
}
